"""
订阅管理相关的数据模型
"""

from pydantic import BaseModel
from typing import Optional, Dict, Any


class SubscriptionCreateRequest(BaseModel):
    """创建订阅请求模型"""
    customer_id: str
    product_id: str
    payment_behavior: str = "default_incomplete"
    metadata: Optional[Dict[str, str]] = None


class SubscriptionCheckoutRequest(BaseModel):
    """创建订阅支付会话请求模型"""
    customer_id: str
    product_id: str
    success_url: str = "http://localhost:8003/subscription/success?session_id={CHECKOUT_SESSION_ID}"
    cancel_url: str = "http://localhost:8003/subscription/cancel"
    metadata: Optional[Dict[str, str]] = None


class SubscriptionUpdateRequest(BaseModel):
    """更新订阅请求模型"""
    metadata: Optional[Dict[str, str]] = None


class SubscriptionUpgradeRequest(BaseModel):
    """升级/降级订阅请求模型"""
    new_product_id: str
    proration_behavior: str = "create_prorations"  # create_prorations, none, always_invoice
    billing_cycle_anchor: str = "now"  # now, unchanged
    metadata: Optional[Dict[str, str]] = None


class SubscriptionResponse(BaseModel):
    """订阅响应模型"""
    id: str
    stripe_subscription_id: str
    customer_id: str
    product_id: str
    status: str
    current_period_start: Optional[int] = None
    current_period_end: Optional[int] = None
    cancel_at_period_end: bool
    metadata: Dict[str, str]
    created_at: str
    updated_at: str
